package cn.tedu.hospital.hosppm.service.impl;

import cn.tedu.hospital.hosppm.mapper.HosppmMapper;
import cn.tedu.hospital.hosppm.pojo.dto.HosppmQuery;
import cn.tedu.hospital.hosppm.pojo.vo.HosppmVO;
import cn.tedu.hospital.hosppm.service.HosppmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;

@Slf4j
@Service
public class HosppmServiceImpl implements HosppmService {
    @Autowired
    private HosppmMapper hosppmMapper;
    @Override
    public List<HosppmVO> select(HosppmQuery hosppmQuery) {
        log.debug("开始查询住院病人信息-入参:{}", hosppmQuery);
        List<HosppmVO> listHosppmVO = hosppmMapper.select(hosppmQuery);
        for (int i = 0; i < listHosppmVO.size(); i++){
            HosppmVO hosppmVO = listHosppmVO.get(i);
            assignescortAndRelation(hosppmVO);
            }
        return listHosppmVO;
    }

    @Override
    public List<HosppmVO> selectByDepartmentName() {
        log.debug("Service开始处理【查询科室名】的请求");
        List<HosppmVO> listDepartmentName = hosppmMapper.selectByDepartmentName();
        return listDepartmentName;
    }

    private void assignescortAndRelation(HosppmVO hosppmVO) {
        List<String> escortAndRelation = new ArrayList<>();
        escortAndRelation.add(hosppmVO.getEscorts());
        escortAndRelation.add(hosppmVO.getEscortRelation());
        StringJoiner stringJoiner = new StringJoiner("(", "", ")");
        for (String escorts : escortAndRelation) {
            stringJoiner.add(escorts);
        }
        System.out.println(stringJoiner);
        hosppmVO.setEscortAndRelation(stringJoiner.toString());
    }



}
